package com.telchina.common.controller;

import com.telchina.common.annotation.Log;
import com.telchina.common.core.controller.BaseController;
import com.telchina.common.core.domain.AjaxResult;
import com.telchina.common.domain.WoDeptHandled;
import com.telchina.common.enums.BusinessType;
import com.telchina.common.service.IWoDeptHandledService;
import com.telchina.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单位经办人Controller
 *
 * @author konghao
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/common/deptHandled")
public class WoDeptHandledController extends BaseController {
    @Autowired
    private IWoDeptHandledService woDeptHandledService;

    /**
     * 分页查询单位经办人列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:list')")
    @GetMapping("/list")
    public AjaxResult list(WoDeptHandled woDeptHandled) {
//        IPage<WoDeptHandled> list = woDeptHandledService.selectList(startPage(), woDeptHandled);
        List<WoDeptHandled> list = woDeptHandledService.selectListAll(woDeptHandled);
        return AjaxResult.success(list);
    }

    /**
     * 查询单位经办人列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(WoDeptHandled woDeptHandled) {
        List<WoDeptHandled> list = woDeptHandledService.selectListAll(woDeptHandled);
        return AjaxResult.success(list);
    }

    /**
     * 导出单位经办人列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:export')")
    @Log(title = "单位经办人" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WoDeptHandled woDeptHandled) {
        List<WoDeptHandled> list = woDeptHandledService.selectListAll(woDeptHandled);
        ExcelUtil<WoDeptHandled> util = new ExcelUtil<WoDeptHandled>(WoDeptHandled.class);
        return util.exportExcel(list, "deptHandle");
    }

    /**
     * 获取单位经办人详细信息
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(woDeptHandledService.selectById(id));
    }

    /**
     * 获取单位经办人详细信息
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:query')")
    @GetMapping(value = "/getDeptHandledInfoByDeptId/{deptId}")
    public AjaxResult getDeptHandledInfoByDeptId(@PathVariable("deptId") String deptId) {
        return AjaxResult.success(woDeptHandledService.getDeptHandledInfoByDeptId(deptId));
    }

    /**
     * 新增单位经办人
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:add')")
    @Log(title = "单位经办人" , businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody WoDeptHandled woDeptHandled) {
        return AjaxResult.success(woDeptHandledService.insert(woDeptHandled));
    }

    /**
     * 修改单位经办人
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:edit')")
    @Log(title = "单位经办人" , businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update")
    public AjaxResult edit(@RequestBody WoDeptHandled woDeptHandled) {
        return AjaxResult.success(woDeptHandledService.update(woDeptHandled));
    }

    /**
     * 删除单位经办人
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:remove')")
    @Log(title = "单位经办人" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return woDeptHandledService.deleteByIds(ids);
    }
}
